package com.qf.homework.service.impl;

import com.qf.homework.cache.MyCache;
import com.qf.homework.entity.User;
import com.qf.homework.service.UserService;
import lombok.Singular;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

@Service
@Scope("singleton")
public class UserServiceImpl implements UserService {


    private MyCache userCache=new MyCache(100);

    @Override
    public boolean containsUsername(String username) {
       return userCache.containsKey(username);
    }

    @Override
    public boolean verifyUser(User user){
        if (containsUsername(user.getUsername())){
            return false;
        }else {
            userCache.put(user.getUsername(),user);
            return true;
        }
    }

}
